package util;

public class ExecutionTimer {
	private long start;
	private long end;

	public ExecutionTimer() {
		reset();
	}

	public void start() {
		start = System.currentTimeMillis();
	}

	public void end() {
		end = System.currentTimeMillis();
	}

	public long duration() {
		return (end - start);
	}

	public double durationInSec() {
		return (end - start) / 1000.0;
	}

	public void endAndPrint() {
		this.end();
		if (this.duration() > 1000) {
			System.out.print(this.durationInSec() + " s");
		} else {
			System.out.print(this.duration() + " ms");
		}
	}

	public void endAndPrintln() {
		this.end();
		if (this.duration() > 1000) {
			System.out.println(this.durationInSec() + " s");
		} else {
			System.out.println(this.duration() + " ms");
		}
	}

	public void reset() {
		start = 0;
		end = 0;
	}
}
